﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DisplayBoardInfo.Server.Forms.Administrator
{
    public partial class BoardsToDisplay : UserControl
    {
        public event EventHandler IndexesChanged;
        public event EventHandler TimeChanged;

        List<Board.Board> boards;

        public BoardsToDisplay()
        {
            InitializeComponent();
        }

        public int[] SelectedIndexes
        {
            get
            {
                List<int> output = new List<int>();
                foreach (Control item in listPanel.Controls)
                {
                    CheckBox ch = (CheckBox)item;
                    if (ch.Checked == true) output.Add(Int32.Parse(ch.Name));
                }
                return output.ToArray();
            }
        }

        public List<Board.Board> Boards
        {
            get { return boards; }
            set 
            { 
                boards = value;
                RefreshList();
            }
        }

        public int DisplayInterval
        {
            get
            {
                return (int)timeNumericUpDown.Value;
            }
        }

        private void RefreshList()
        {
            listPanel.Controls.Clear();
            if (boards != null)
            {
                int currentLocation = 3;
                int i = 0;
                foreach (Board.Board item in boards)
                {
                    CheckBox ch = new CheckBox();
                    ch.Text = item.ToString();
                    ch.Location = new Point(3, currentLocation);
                    currentLocation += 23;
                    ch.Name = i.ToString();
                    i++;
                    ch.AutoSize = true;
                    ch.Size = new System.Drawing.Size(80, 17);
                    ch.UseVisualStyleBackColor = true;
                    ch.CheckedChanged += new EventHandler(ch_CheckedChanged);
                    listPanel.Controls.Add(ch);
                }
            }
        }

        void ch_CheckedChanged(object sender, EventArgs e)
        {
            IndexesChanged(this, new EventArgs());
        }

        private void allButton_Click(object sender, EventArgs e)
        {
            foreach (Control item in listPanel.Controls)
            {
                CheckBox ch = (CheckBox)item;
                ch.Checked = true;
            }
        }

        private void timeNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            TimeChanged(this, new EventArgs());
        }

    }
}
